package red.mlz.articleservice.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import red.mlz.articleservice.service.ArticleService;
import red.mlz.common.entity.article.Article;

import java.math.BigInteger;
import java.util.List;

@RestController
@Slf4j
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/article-service/getArticlesTotalForConsole")
    public int getArticlesTotalForConsole(@RequestParam(name = "title")String title){
        return articleService.getArticlesTotalForConsole(title);
    }

    @RequestMapping("/article-service/getArticlesForConsole")
    public List<Article> getArticlesForConsole(@RequestParam(name = "page") int page,
                                               @RequestParam(name = "pageSize") int pageSize,
                                               @RequestParam(name = "title") String title){
        return articleService.getArticlesForConsole(page, pageSize, title);
    }

    @RequestMapping("/article-service/getArticleList")
    public List<Article> getArticleList (@RequestParam(name = "page") int page,
                                 @RequestParam(name = "pageSize") int pageSize,
                                 @RequestParam(name = "key")String key){
        return articleService.getArticleList(page,pageSize,key);
    }

    @RequestMapping("/article-service/extractById")
    public Article articleInfo(@RequestParam(name = "articleId") BigInteger articleId){
        return articleService.extractById(articleId);
    }

    @RequestMapping("/article-service/getById")
    public Article getById(@RequestParam(name = "articleId") BigInteger articleId){
        return articleService.getById(articleId);
    }

    @RequestMapping("/article-service/editArticle")
    public BigInteger editArticle(@RequestParam(name = "article") BigInteger articleId,
                       @RequestParam(name = "relateShopId")BigInteger relateShopId,
                       @RequestParam(name = "title")String title,
                       @RequestParam(name = "coverImage")String coverImage,
                       @RequestParam(name = "tags")String tags,
                       @RequestParam(name = "content")String content,
                       @RequestParam(name = "weight")Integer weight){
        return articleService.editArticle(articleId,relateShopId,title, coverImage, tags, content, weight);
    }

    @RequestMapping("/article-service/delete")
    public void delete(@RequestParam(name = "articleId") BigInteger articleId){
        articleService.delete(articleId);
    }

}
